package org.txazo.music.util;

import java.util.regex.Pattern;

/**
 * 正则表达式工具类
 * 
 * @author Tu XiaoZhou
 * @since 2013-04-19
 * 
 */
public class PatternUtil {

	public static final Pattern REGEX_PATTERN_EMAIL = Pattern
			.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
	public static final Pattern REGEX_PATTERN_NUMANDCHAR = Pattern
			.compile("^[A-Za-z0-9]{6,18}$");
	public static final Pattern REGEX_PATTERN_NUMANDCHARBEGIN = Pattern
			.compile("^[A-Za-z][A-Za-z0-9]{5,17}$");
	public static final Pattern REGEX_PATTERN_CHINESE = Pattern
			.compile("^[\u4e00-\u9fa5]+$");

	/**
	 * 是否匹配电子邮件
	 */
	public static boolean matchEmail(String str) {
		return REGEX_PATTERN_EMAIL.matcher(str).matches();
	}

	/**
	 * 是否匹配数字和字母组成的6到18位字符串
	 */
	public static boolean matchNumAndChar(String str) {
		return REGEX_PATTERN_NUMANDCHAR.matcher(str).matches();
	}

	/**
	 * 是否匹配数字和字母组成字母开头的6到18位字符串
	 */
	public static boolean matchNumAndCharBegin(String str) {
		return REGEX_PATTERN_NUMANDCHARBEGIN.matcher(str).matches();
	}

	/**
	 * 是否匹配中文
	 */
	public static boolean matchChinese(String str) {
		return REGEX_PATTERN_CHINESE.matcher(str).matches();
	}

}
